/**
 * https://leetcode.cn/problems/longest-substring-without-repeating-characters/
 * 3. 无重复字符的最长子串
 * medium, 赖德檀 2024.09.02
 * 滑动窗口
 */

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        vector<int>arr(256,-1);
        int sum=0;
        for(int l=0,r=0;r<s.size();r++)
        {
            l=max(l,arr[s[r]]+1);
            sum=max(sum,r-l+1);
            arr[s[r]]=r;
        }
        return sum;
    }
};